package Views;

import Dao.NoPara;
import Dao.OnePara;
import Dao.TwoPara;

import java.util.Scanner;

/**
 * 执行课程信息操作
 * @author 秦亚辉
 */
public class CourseView {
    private NoPara noPara;
    public void mainView() {
        noPara = new NoPara();
        boolean con = false;

        do {
            System.out.println("执行课程信息操作");
            System.out.println("****************************************");
            System.out.println("\n\t\t1.添加课程\n");
            System.out.println("\t\t2.更改课程\n");
            System.out.println("\t\t3.删除课程\n");
            System.out.println("****************************************");
            System.out.println("请选择,输入数字或者按0返回上一级菜单：");
            Scanner input = new Scanner(System.in);
            int num = input.nextInt();
            switch (num) {
                case 0:
                    MainPage mainPage = new MainPage();
                    mainPage.mainMenu();
                    break;
                case 1:
                    String flag1="";
                    do {
                        System.out.println("请输入课程名：");
                        String courseName = input.next();

                        /**
                         *
                          * mysql插入列，列名就是课程名‘
                        * */
                        noPara.addCourse(courseName);
                        System.out.println("是否继续？y or n");
                        flag1=input.next();
                    }while ("y".equals(flag1));
                    con=true;
                    break;
                case 2:
                    String flag2="";
                    do {
                        System.out.println("请输入要更改的课程名：");
                        String oldName= input.next();
                        System.out.println("请输入新课程名：");
                        String newName = input.next();
                        noPara.renameCourse(oldName,newName);
                        System.out.println("是否继续？y or n");
                        flag2=input.next();
                    }while ("y".equals(flag2));
                    con=true;
                    break;
                case 3:
                    String flag3="";
                    do {
                        System.out.println("请输入要删除的课程名");
                        String deleteCourse = input.next();
                        noPara.deletcourse(deleteCourse);
                        System.out.println("是否继续？y or n");
                        flag3=input.next();
                    }while ("y".equals(flag3));
                    con = true;
                    break;
                default:
                    System.out.println("\n输入错误，请重新输入");
                    con = true;
                    break;

            }

        }while (con) ;
    }
}
